<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<form action="http://127.0.0.1:3000/api/users/uploads" method="post" enctype="multipart/form-data">
    <input type="file" name="headimg"/>
    <button type="submit">提交</button>
</form>
<hr>

<button onclick="gx()">更新用户信息</button>
<hr>
<button onclick="login()">登入</button>
<hr>
<button onclick="addwz()">添加文章</button>
<hr>
<button onclick="getarticele()">获取文章信息</button>
<hr>
<button onclick="getall()">获取所有的文章</button>
<hr>
<button onclick="delar()">删除文章</button>
<hr>
<button onclick="upar()">修改文章</button>
</body>
<script>
    axios.interceptors.response.use(function (res){
        return res.data;
    });

    axios.interceptors.request.use(function (res){
        let token=sessionStorage.getItem('token');
        res.headers.Authorization=token;
        return res;
    })

async function login() {
    let res = await axios.post('http://localhost:3000/api/users/login', {
        username: 'admin2',
        password: 'admin'
    });
    sessionStorage.setItem('token',res.data.token);
}

async function gx() {
    let res = await axios.put('http://localhost:3000/api/users/updateuser', {
        nickname: '羡羡201',
        headimg: 'https://'
    });
    console.log(res);
    console.log(res.data.nickname);
}

async function addwz() {
    let res = await axios.post('http://localhost:3000/api/article/addarticle',{
        title:'vue入门',
        arcontext:'<h1>测试vue</h1>'
    });
    console.log(res);
}

async function getarticele() {
    let res = await axios.get('http://localhost:3000/api/article/detail',{
        params:{
            id:2
        }
    });
    console.log(res);
}

async function getall() {
    let res = await axios.get('http://localhost:3000/api/article/allartlist');
    console.log(res);
};
    async function delar() {
        let res = await axios.delete('http://localhost:3000/api/article/7');
        console.log(res);
    }

    async function upar() {
        let res = await axios.put('http://localhost:3000/api/article/editarticle',{
            id:6,
            title: 'react入门',
            arcontext: '<h1>JXL</h1>'
        });
        console.log(res);
    }


</script>
</html>
